package io.renren.modules.generator.dao;

import io.renren.modules.generator.entity.EcharsData;
import io.renren.modules.generator.entity.SysLogininforEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 系统访问记录
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-11-28 16:55:56
 */
@Mapper
public interface SysLogininforDao extends BaseMapper<SysLogininforEntity> {

    /**
     * 按月份排序
     * @return
     */

    @Select("SELECT count(*) FROM `sys_logininfor` where MONTH(login_time)=#{monthNum} and YEAR(login_time)=#{yearNum}")
    Integer  selectVisitorsOfMonth(String monthNum,String yearNum);
    /**
     * 查询每个省份的访问人数
     * @return
     */
    @Select("SELECT left(login_location,2) as xAxisData,  count(*) as seriesData FROM `sys_logininfor` GROUP BY left(login_location,2)")
    List<EcharsData> selectProvinceAndNum();

    /**
     * 查询今天访问人数
     * @return
     */
    @Select("select count(*) from sys_logininfor where date(login_time) = curdate()")
    Integer getTodayVisitNum();

    /**
     * 查询总访问人数
     * @return
     */
    @Select("select count(*)  from sys_logininfor")
    Integer getAllVisitNum();

}
